package ru.timus.acm.p1002;

import java.io.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;

public class Main {

    static int convert(char c) {
        switch (c) {
            case '1':
            case 'i':
            case 'j':
                return 1;
            case '2':
            case 'a':
            case 'b':
            case 'c':
                return 2;
            case '3':
            case 'd':
            case 'e':
            case 'f':
                return 3;
            case '4':
            case 'g':
            case 'h':
                return 4;
            case '5':
            case 'k':
            case 'l':
                return 5;
            case '6':
            case 'm':
            case 'n':
                return 6;
            case '7':
            case 'p':
            case 'r':
            case 's':
                return 7;
            case '8':
            case 't':
            case 'u':
            case 'v':
                return 8;
            case '9':
            case 'w':
            case 'x':
            case 'y':
                return 9;
            case '0':
            case 'o':
            case 'q':
            case 'z':
                return 0;
            default:
                throw new IllegalArgumentException();
        }
    }

    static int[] convert(char[] s) {
        int[] result = new int[s.length];
        for (int i = 0; i < s.length; i++) {
            result[i] = convert(s[i]);
        }
        return result;
    }

    static class Trie {
        char[] values;
        Trie[] children = new Trie[10];

        boolean isLeaf() {
            return values != null;
        }

        void put(char[] values) {
            put(values, 0);
        }

        void put(char[] values, int index) {
            int converted = convert(values[index]);
            Trie child = children[converted] = children[converted] != null ? children[converted] : new Trie();
            if (index == values.length - 1) child.values = values;
            if (index < values.length - 1) {
                child.put(values, index + 1);
            }
        }

        Trie get(int[] convertedValues, int index) {
            int converted = convertedValues[index];
            return children[converted];
        }

    }

    int[] numberIntArray;
    Trie trie;
//    char[][][] cache;
    Solution[] cache2;

    Main(char[] numberCharArray, char[][] wordsCharArrays) {
        this.numberIntArray = convert(numberCharArray);
        this.trie = new Trie();
        for (char[] word : wordsCharArrays) {
            trie.put(word);
        }
//        this.cache = new char[this.numberIntArray.length][][];
        this.cache2 = new Solution[this.numberIntArray.length+1];
    }

    char[][] words(int index) {
        Collection<char[]> result = new HashSet<char[]>();
        Trie trie = this.trie;
        int index0 = index;
        while (true) {
            if (index == numberIntArray.length || index - index0 > 50) {
                return result.toArray(new char[result.size()][]);
            }
            Trie child = trie.get(numberIntArray, index);
            if (child == null) {
                return result.toArray(new char[result.size()][]);
            }
            if (child.isLeaf()) {
                result.add(child.values);
            }
            trie = child;
            index++;
        }
    }

//    char[][] wordsSorted(int index) {
//        char[][] result = words(index);
//        Arrays.sort(result, new Comparator<char[]>() {
//            @Override
//            public int compare(char[] o1, char[] o2) {
//                return o2.length - o1.length;
//            }
//        });
//        return result;
//    }

//    char[][] wordsCached(int index) {
//        char[][] result = cache[index];
//        if (result == null) {
//            result = wordsSorted(index);
//            cache[index] = result;
//        }
//        return result;
//    }

    static class Solution {
        String value;
        int length;

        Solution(String value, int length) {
            this.value = value;
            this.length = length;
        }
    }

    Solution best(int index) {
        if (index == numberIntArray.length) {
            return new Solution("", 0);
        }
        char[][] words = words(index);
        if (words.length == 0) {
            return new Solution(null, Integer.MAX_VALUE);
        }
        Solution bestSubSolution = new Solution(null, Integer.MAX_VALUE);
        char[] bestWord = null;
        for (char[] word : words) {
            Solution subSolution = cachedBest(index + word.length);
            if (subSolution.value == null) {
                continue;
            }
            if (subSolution.length < bestSubSolution.length) {
                bestSubSolution = subSolution;
                bestWord = word;
            }
        }
        return bestWord == null ? bestSubSolution : new Solution(new String(bestWord) + (bestSubSolution.length == 0 ? "" : " ") + bestSubSolution.value, bestSubSolution.length + 1);
    }

    Solution cachedBest(int index) {
        Solution result = cache2[index];
        if (result == null) {
            result = best(index);
            cache2[index] = result;
        }
        return result;
    }

    String getSolution() {
        Solution solution = cachedBest(0);
        return solution.value == null ? "No solution." : solution.value;
    }

    public static void main(String[] args) throws IOException {
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        BufferedReader in = oj ? new BufferedReader(new InputStreamReader(System.in)) : new BufferedReader(new FileReader("1002.txt"));
        while (true) {
            String numberString = in.readLine();
            if (numberString == null || "-1".equals(numberString)) break;
            int wordsNumber = Integer.parseInt(in.readLine());
            char[][] wordsCharArrays = new char[wordsNumber][];
            for (int i = 0; i < wordsNumber; i++) {
                wordsCharArrays[i] = in.readLine().toCharArray();
            }
            System.out.println(new Main(numberString.toCharArray(), wordsCharArrays).getSolution());
        }
    }

}